<div class="center">
<?php
if ($handle = opendir(PHOTO_GALLERY_PATH)) {
  while ($file = readdir($handle)) {
      if(isdir($file) && $file != ".." && $file != ".")
        $polozky[count($polozky)] = $file;
  } 
  closedir($handle);
  if(count($polozky) > 0) {
    rsort($polozky);
    reset($polozky);
  }
}

echo "<table class='centered medium-table'>";
echo "<colgroup>";
  echo "<col width='1'>";
  echo "<col width='1'>";
  echo "<col width='1'>";
  echo "<col width='1'>";
echo "</colgroup>";

$i = 0;

if(count($polozky) > 0) {
  while (list($key, $val) = each($polozky)) {
    if($i % 4 == 0) echo "<tr>";
    echo "<td valign='top'>";
    $gal_dir = PHOTO_GALLERY_PATH."/".$val;
    if($handle = opendir($gal_dir)) {
      while($file = readdir($handle)) {
        if(isdir($file) && strpos($file, "small") !== false) {
          $handle2 = opendir($gal_dir."/".$file);
          while($small_file = readdir($handle2)){
            if(isfile($small_file)){
              $path = $gal_dir."/small/".$small_file;
              echo "<a class='img-link preloader' href='".redirect_str(PAGE_PHOTOS).add_par("album=".$val)."'><img class='pic' src='$path'></a><br>";
              break;
            }
          }
        }
      }
      closedir($handle);
    }
    echo "$val</td>";
    if(($i+1) % 4 == 0) echo "</tr>";  
    $i++;
  }
}
echo "</table>";
?>
</div>